import React, { Component, PropTypes } from 'react';

class Image extends Component {
    static propTypes = {
        src:PropTypes.string.isRequired,
        width:PropTypes.oneOf([PropTypes.number,PropTypes.string]),
        height:PropTypes.oneOf([PropTypes.number,PropTypes.string]),
        alt:PropTypes.string,
    
    };
    static defaultProps = {
        className:"ant-table-row-img",
        width:70,
        height:70,
        auto:false,//不添加宽高限制，原图展示
    }
    render() {
        const { className, width, height, auto, src, ...rest} = this.props;
        if(!src){
            return null;
        }
        let url = src;
        if(/^https?:\/\//.test(url)){
            url = url.replace(/https?:\/\//,"//");
        }else if(!/^\/\//.test(url)){
            url = ($CONST_HOST['v_oss_domain_img'] + $CONST_HOST['v_oss_path_img']).replace('${filePath}', url);
        }
        //如果已经包含了压缩参数，就不追加了
        if(!auto && url.indexOf("@") === -1){
            url = `${url}@${width}w_${height}h_1e`
        }

        return (
            <img src={url} className={className}  {...rest}/>
        );
    }
}

export default Image;